package com.pluten.basicinfo.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.pluten.common.core.domain.entity.SysUser;
import com.pluten.common.utils.CacheUtil;
import com.pluten.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.pluten.basicinfo.mapper.CmProductCategoryMapper;
import com.pluten.basicinfo.domain.CmProductCategory;
import com.pluten.basicinfo.service.ICmProductCategoryService;

/**
 * 产品类别Service业务层处理
 *
 * @author wangjun
 * @date 2021-08-24
 */
@Service
public class CmProductCategoryServiceImpl implements ICmProductCategoryService {
    @Autowired
    private CmProductCategoryMapper cmProductCategoryMapper;

    /**
     * 查询产品类别
     *
     * @param guid 产品类别ID
     * @return 产品类别
     */
    @Override
    public CmProductCategory selectCmProductCategoryById(Long guid) {
        return cmProductCategoryMapper.selectCmProductCategoryById(guid);
    }

    /**
     * 查询产品类别列表
     *
     * @param cmProductCategory 产品类别
     * @return 产品类别
     */
    @Override
    public List<CmProductCategory> selectCmProductCategoryList(CmProductCategory cmProductCategory) {
        List<CmProductCategory> cmProductCategories = cmProductCategoryMapper.selectCmProductCategoryList(cmProductCategory);
        List<SysUser> userList = CacheUtil.getUserList();
        Map<Long, SysUser> userMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId, v -> v, (k1, k2) -> k1));
        for (CmProductCategory productCategory : cmProductCategories) {
            String createBy = productCategory.getCreateBy();
        }
        return cmProductCategories;
    }

    /**
     * 新增产品类别
     *
     * @param cmProductCategory 产品类别
     * @return 结果
     */
    @Override
    public int insertCmProductCategory(CmProductCategory cmProductCategory) {
        cmProductCategory.setCreateTime(DateUtils.getNowDate());
        return cmProductCategoryMapper.insertCmProductCategory(cmProductCategory);
    }

    /**
     * 修改产品类别
     *
     * @param cmProductCategory 产品类别
     * @return 结果
     */
    @Override
    public int updateCmProductCategory(CmProductCategory cmProductCategory) {
        cmProductCategory.setUpdateTime(DateUtils.getNowDate());
        return cmProductCategoryMapper.updateCmProductCategory(cmProductCategory);
    }

    /**
     * 批量删除产品类别
     *
     * @param guids 需要删除的产品类别ID
     * @return 结果
     */
    @Override
    public int deleteCmProductCategoryByIds(Long[] guids) {
        return cmProductCategoryMapper.deleteCmProductCategoryByIds(guids);
    }

    /**
     * 删除产品类别信息
     *
     * @param guid 产品类别ID
     * @return 结果
     */
    @Override
    public int deleteCmProductCategoryById(Long guid) {
        return cmProductCategoryMapper.deleteCmProductCategoryById(guid);
    }
}
